#include <bits/stdc++.h>

#define in read()
#define fi first
#define se second
#define pb push_back
#define rep(i, x, y) for(int i = (x); i <= (y); i++)
#define per(i, x, y) for(int i = (x); i >= (y); i--)

using namespace std;

typedef long long ll;
typedef double db;
typedef vector < int > vec;
typedef pair < int , int > pii;

int read() {
    int x = 0; bool f = 0; char ch = getchar(); while(!isdigit(ch)) f |= ch == '-',ch = getchar();
    while(isdigit(ch)) x = x * 10 + (ch ^ 48),ch = getchar(); return f ? -x : x;
}

const int N = 1e5 + 10;
const int inf = 0x3f3f3f3f;

int n, m;

const int H[4][2] = { 0, -1, 0, 1, 1, 0, -1, 0 };
const char D[4] = { 'L', 'R', 'D', 'U' };

namespace F { // max_flow_with_cost
	const int M = N << 2;
    int h[N], now[N], cnt = 1, S, T;
    bool vis[N];
    ll maxflow,cost,dis[N];
    struct edge { int v,w,c,nxt; } e[M << 1];
    inline void tlink(int x,int y,int w,int c) { e[++cnt] = (edge) { y,w,c,h[x] }; h[x] = cnt; }
    inline void link(int x,int y,int w,int c) { tlink(x,y,w,c); tlink(y,x,0,-c); }
    inline void setst(int s,int t) { S = s; T = t; }
	void reset() { rep(i, 0, n * m + 1) h[i] = 0; cnt = 1; }
    bool bfs() {
		queue < int > q; q.push(S); rep(i, 0, n * m + 1) vis[i] = 0, dis[i] = inf; dis[S] = 0; now[S] = h[S]; vis[S] = 1;
		while(!q.empty()) {
			int x = q.front(); q.pop();
			for(int i = h[x],y;i;i = e[i].nxt)
				if(e[i].w && dis[y = e[i].v] > dis[x] + e[i].c) {
					dis[y] = dis[x] + e[i].c; now[y] = h[y];
					if(!vis[y]) vis[y] = 1,q.push(y);
				}
			vis[x] = 0;
		} return dis[T] < inf;
    }
    int dinic(int x,int flow,ll c) {
		if(x == T) return maxflow += flow,cost += c * flow,flow;
		int res = flow; vis[x] = 1;
		for(int i = now[x],y;i && res;i = e[i].nxt) {
			now[x] = i;
			if(e[i].w && dis[y = e[i].v] == dis[x] + e[i].c && !vis[y]) {
				int k = dinic(y,min(res,e[i].w),c + e[i].c); 
				e[i].w -= k; e[i ^ 1].w += k; res -= k;
			}
		} vis[x] = 0;
		return flow - res;
    }
    void runit() { cost = 0; maxflow = 0; while(bfs()) dinic(S,inf,0); }
}

int indx[N], indy[N];

int getid(int dx, int dy) {
	rep(i, 0, 3) if(H[i][0] == dx && H[i][1] == dy) return i + 1;
	assert(0);
}

void solve() {
	F :: reset(); 
	n = in, m = in; if(n == 1 && m == 1) return puts("NO"), void();
	vector < vec > id, s, a, mustc, dir;
	id = s = a = mustc = dir = vector < vec > (n + 1, vec(m + 1, 0));
	int tot = 0; 
	rep(i, 1, n) rep(j, 1, m) id[i][j] = ++tot, indx[tot] = i, indy[tot] = j;
	F :: setst(0, ++tot); 
	rep(i, 1, n) rep(j, 1, m) s[i][j] = in;
	int sum = 0;
	rep(i, 1, n) {
		rep(j, 1, m) {
			mustc[i][j] = 1;
			rep(k, 0, 3) {
				int x = i + H[k][0], y = j + H[k][1];
				if(x > 0 && y > 0 && x <= n && y <= m) {
					if(s[x][y] < s[i][j]) { mustc[i][j] = 0; break; }
				}
			}
			sum += mustc[i][j];
		}
	}
	rep(i, 1, n) {
		rep(j, 1, m) {
			if(i + j & 1) continue;
			rep(k, 0, 3) {
				int x = i + H[k][0], y = j + H[k][1];
				if(x > 0 && y > 0 && x <= n && y <= m && s[x][y] == s[i][j])
					F :: link(id[i][j], id[x][y], 1, 0);
			}
		}
	}
	rep(i, 1, n) {
		rep(j, 1, m) {
			if(i + j & 1) F :: link(id[i][j], F :: T, 1, -mustc[i][j]);
			else F :: link(F :: S, id[i][j], 1, -mustc[i][j]);
		}
	}
	F :: runit(); if(-sum != F :: cost) return puts("NO"), void();
	for(int i = F :: h[0]; i; i = F :: e[i].nxt) {
		int u = F :: e[i].v; if(F :: e[i].w == 1) continue;
		for(int j = F :: h[u]; j; j = F :: e[j].nxt) {
			if(F :: e[j].w == 1) continue;
			int v = F :: e[j].v;
			int x = indx[u], y = indy[u], nx = indx[v], ny = indy[v];
			dir[x][y] = getid(nx - x, ny - y);
			dir[nx][ny] = getid(x - nx, y - ny);
			a[x][y] = 1; a[nx][ny] = s[x][y] - 1;
		}
	}
	rep(i, 1, n)
		rep(j, 1, m)
		if(!dir[i][j])
			rep(k, 0, 3) {
				int x = i + H[k][0], y = j + H[k][1];
				if(x > 0 && y > 0 && x <= n && y <= m) {
					if(s[x][y] < s[i][j]) { dir[i][j] = k + 1; a[i][j] = s[i][j] - s[x][y]; break; }
				}
			}
	puts("YES");
	rep(i, 1, n) rep(j, 1, m) printf("%d%c", a[i][j], " \n"[j == m]);
	rep(i, 1, n) rep(j, 1, m) printf("%c%c", D[dir[i][j] - 1], " \n"[j == m]);
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("1.in","r",stdin);
#endif
    int T = in; while(T--) solve(); return 0;
}
